<template>
    <el-card class="box-card">
        <div slot="header" class="category-header">
            <span>销售累额占比</span>
            <div>
                <el-radio-group v-model="radio1" size="small">
                    <el-radio-button label="全部渠道"></el-radio-button>
                    <el-radio-button label="线上"></el-radio-button>
                    <el-radio-button label="门店"></el-radio-button>
                </el-radio-group>
            </div>
        </div>
        <div>
            <div class="charts" ref="charts"></div>
        </div>
    </el-card>
</template>

<script>
import * as echarts from "echarts"
export default {
    name: "Category",
    data() {
        return {
            radio1: "全部渠道",
        }
    },
    mounted() {
        const myChart = echarts.init(this.$refs.charts)
        const option = {
            title: {
                text: "视频广告",
                subtext: 335,
                top: "middle",
                left: "middle",
                textAlign: "center",
            },
            tooltip: {
                trigger: "item",
            },
            series: [
                {
                    type: "pie",
                    data: [
                        {
                            value: 335,
                            name: "视频广告:335",
                        },
                        {
                            value: 234,
                            name: "搜索引擎:234",
                        },
                        {
                            value: 1000,
                            name: "联盟广告:1000",
                        },
                        {
                            value: 700,
                            name: "邮件营销:700",
                        },
                    ],
                    emphasis: {
                        label: {
                            show: true,
                        },
                    },
                    label: {
                        show: true,
                        position: "outside",
                    },
                    labelLine: {
                        show: true,
                    },
                    radius: ["40%", "70%"],
                    itemStyle: {
                        borderColor: "#fff",
                        borderWidth: 2,
                    },
                },
            ],
        }
        myChart.setOption(option)
        // charts的事件绑定
        myChart.on("mouseover", (params) => {
            myChart.setOption({
                title: {
                    text: params.data.name.split(":")[0],
                    subtext: params.data.value,
                },
            })
        })
    },
}
</script>

<style>
.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
</style>